package zuoye;

/**
 * 1：新增课程，通过控制台输入信息，保存到subject表中
 */
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Scanner;

public class InsertSubject {
	public static void main(String[] args) {
		Connection conn = DBUtil.getConnection();
		PreparedStatement ps = null;
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入要新增的科目名：");
		String name = sc.next();
		System.out.println("请输入课时：");
		int hour = sc.nextInt();
		System.out.println("请输入年级id：");
		int graid = sc.nextInt();
		String sql = "insert into subject(subjectname,classhour,gradeid) values(?,?,?)";
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1, name);
			ps.setInt(2, hour);
			ps.setInt(3, graid);
			ps.executeUpdate();
			System.out.println("成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			DBUtil.close(ps);
			DBUtil.close(conn);
		}

	}
}
